package routers

import (
	"github.com/gin-gonic/gin"
	"goadmin/controllers/admin"
	"goadmin/middlewares"
)

func AdminRoutersInit(r *gin.Engine) {

	notLoginRouters := r.Group("/admin")
	{
		notLoginRouters.POST("/login", admin.LoginController{}.DoLogin)
		notLoginRouters.GET("/", admin.MainController{}.Index)
	}

	//middlewares.InitMiddleware,需要用到中间件的路由
	// middlewares.InitAdminAuthMiddleware
	adminRouters := r.Group("/admin", middlewares.PaginationMiddleware())
	{
		adminRouters.GET("/welcome", admin.MainController{}.Welcome)
		adminRouters.GET("/user/dashboard", admin.MainController{}.Dashboard)
		adminRouters.GET("/dashboard", admin.MainController{}.Dashboard)
		adminRouters.GET("/getSalesChartOption", admin.MainController{}.SalesChartOption)
		adminRouters.GET("/info", admin.MainController{}.Info)
		//菜单列表
		adminRouters.GET("/menus/allList", admin.MenusController{}.AllList)
		adminRouters.POST("/menu/add", admin.MenusController{}.AddMenus)
		adminRouters.DELETE("/menu/delete/:id", admin.MenusController{}.DeleteMenus)
		adminRouters.PUT("/menu/update/:id", admin.MenusController{}.UpdateMenus)
		//角色列表
		adminRouters.GET("/role/list", admin.RoleController{}.Index)
		adminRouters.PUT("/role/update/:id", admin.RoleController{}.UpdateRole)
		adminRouters.DELETE("/role/delete/:id", admin.RoleController{}.DeleteRole)

		//基础配置
		adminRouters.GET("/config", admin.CofigController{}.Index)
		adminRouters.PUT("/config/:id", admin.CofigController{}.UpdateConfig)
		//管理员列表
		adminRouters.GET("/index", admin.AdminUserController{}.Index)
		adminRouters.PUT("/updateUser", admin.AdminUserController{}.UpdateUser)
		adminRouters.DELETE("/deleteUser/:id", admin.AdminUserController{}.DeleteUser)
		adminRouters.POST("/register", admin.AdminUserController{}.Register)

		//产品路由
		productController := admin.ProductController{}
		adminRouters.GET("/products", productController.Index)
		adminRouters.POST("/products", productController.Create)
		adminRouters.GET("/products/:id", productController.Show)
		adminRouters.PUT("/products/:id", productController.Update)
		adminRouters.DELETE("/products/:id", productController.Delete)
		//获取七牛token
		adminRouters.GET("/generateQiniuToken", admin.UploadController{}.GenerateQiniuToken)
		//获取用户
		adminRouters.GET("/users", admin.UserController{}.GetUserList)
		//获取订单
		adminRouters.GET("/order_record", admin.OrderController{}.OrderList)

	}
}
